<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>watch-属性监听</title>
</head>
<body>
    <main id="app">
        <div>角度：<input type="number" v-model.trim.number.lazy="jd"></div>
        <div>弧度：<input type="number" v-model.trim.number.lazy="hd"></div>
    </main>
</body>
<script src="../../vue.js"></script>
<script>
    let vue = new Vue({
        el: "#app",
        data: {
            jd: 0,
            hd: 0
        },
        watch: {
            /**
             * newVal: 改变后的新值
             * oldVal：改变前的旧值
             * */
            hd(newVal,oldVal) {
                console.log("hd!newVal = ",newVal,",oldVal = ",oldVal);
                this.jd = 180 / Math.PI * newVal;
            }
        }
    });

    // 方法二：也可以使用vue对象.$watch添加监听
    vue.$watch("jd",(newVal,oldVal) => {
        console.log("jd!newVal = ",newVal,",oldVal = ",oldVal);
        vue.hd = Math.PI / 180 * newVal;
        // vue.hd =
    })
</script>
</html>